package com.atguigu06.polymorphism.exer2;

/**
 * ClassName: AnimalTest
 * Package: com.atguigu06.polymorphism.apply
 * Description:
 *
 * @Author 姜
 * @Create 2023/11/22 14:15
 * @Version 1.0
 */
public class AnimalTest {
    public static void main(String[] args) {
        AnimalTest test = new AnimalTest();
        test.adopt(new Dog());
        test.adopt(new Cat());
    }

    public void adopt(Animal animal) {
        animal.eat();
        animal.jump();
        //
        if (animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.watchDoor();
        } else if (animal instanceof Cat) {
            Cat cat = (Cat) animal;
            cat.catchMouse();
        }

    }
}

class Animal {
    public void eat() {
        System.out.println("动物觅食");
    }

    public void jump() {
        System.out.println("跑路");
    }
}

class Dog extends Animal {
    public void eat() {
        System.out.println("狗吃屎");
    }

    public void jump() {
        System.out.println("狗急跳墙");
    }

    public void watchDoor() {
        System.out.println("看家护院");
    }
}

class Cat extends Animal {
    public void eat() {
        System.out.println("猫吃鱼");
    }

    public void jump() {
        System.out.println("猫会后空翻");
    }

    public void catchMouse() {
        System.out.println("抓老鼠");
    }
}
